﻿using CastingWellEquipmentGUI.Config;
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Media;

namespace CastingWellEquipmentGUI.ViewModel.Pages
{
    /// <summary>
    /// 网络连接ViewModel
    /// </summary>
    public class NetConnectPageViewModel : ViewModelBase
    {
        #region 变量/常量

        #endregion 变量/常量

        #region 页面属性
        private Brush _Color_ConnectStatus = Brushes.Red;
        /// <summary>
        /// 网络连接状态
        /// </summary>
        public Brush Color_ConnectStatus
        {
            get { return _Color_ConnectStatus; }
            set { _Color_ConnectStatus = value; RaisePropertyChanged("Color_ConnectStatus"); }
        }
        #endregion 页面属性

        #region 线程对象
        /// <summary>
        /// 动画线程
        /// </summary>
        private Thread tagInfoSyncThread = null;
        #endregion 线程对象

        #region 方法
        public NetConnectPageViewModel()
        {
            // 动画线程
            tagInfoSyncThread = new Thread(syncThreadFunc);
            tagInfoSyncThread.IsBackground = true;
            tagInfoSyncThread.Start();
        }

        /// <summary>
        /// 动画线程
        /// </summary>
        private void syncThreadFunc()
        {
            while (true)
            {
                if (ThreadController.RoundBarNetConnectPageThreadState)
                {
                    // 网络中断不进行消费监听
                    if (SystemConfig.SystemStatus == "网络中断")
                    {
                        Color_ConnectStatus = Brushes.Red;
                    }
                    else
                    {
                        Color_ConnectStatus = Brushes.Green;
                    }
                    Thread.Sleep(1000);
                }
            }
        }

        #endregion 方法
    }
}
